package com.yang.bean.xml;

import com.yang.bean.beanfactory.registry.BeanDefinitionRegistry;
import com.yang.bean.util.DocumentReader;
import org.dom4j.Document;

import java.io.InputStream;

/**
 * @Description: 解析XML
 * @author: Yang Qiang
 * @create: 2021-11-08 21:19
 */
public class XMLBeanDefinitionReader {

    // 注册BeanDefinition的接口
    private BeanDefinitionRegistry beanDefinitionRegistry;

    public XMLBeanDefinitionReader(BeanDefinitionRegistry beanDefinitionRegistry) {
        this.beanDefinitionRegistry = beanDefinitionRegistry;
    }

    /**
     * 把流信息转化为Document
     * @param inputStream
     */
    public void loadBeanDefinition(InputStream inputStream){
        Document document = DocumentReader.createDocument(inputStream);

        DefaultBeanDefinitionDocumentReader documentReader = new DefaultBeanDefinitionDocumentReader(beanDefinitionRegistry);

        documentReader.registryBeanDefinitions(document.getRootElement());
    }
}
